/**
 * @fileoverview 文档支持 - 页面主体自适应页面
 */
(function(){
	

	var win = window;
	
	var clsDocWin = new Class({
		Implements:[Options],
		options:{
			els:{
				box:'container',
				head:'header',
				menu:'menu',
				content:'content',
				foot:'footer'
			},
			minWidth:400,	//内容区域最小宽度
			minHeight:50	//内容区域最小高度
		},
		initialize:function(options){
			this.setOptions(options);
			this.build(this.options);
		},
		build:function(ops){
			this.els = {};
			Object.each(ops.els,function(val,key){
				this.els[key] = $(val);
			}.bind(this));
			
			this.adapt();
			
			this.bound = {
				adapt:this.adapt.bind(this),
				destroy:this.destroy.bind(this)
			};
			this.setEvent('add');
		},
		setEvent:function(motion){
			var m = motion + 'Event', b = this.bound;
			win[m]('resize',b.adapt);
			win[m]('beforeunload',b.destroy);
		},
		adapt:function(){
			var ops = this.options,
				wsize = win.getSize(),
				hsize = this.els.head.getSize(),
				fsize = this.els.foot.getSize(),
				msize = this.els.menu.getSize(),
				areaWidth = Math.max( wsize.x - msize.x - 3, ops.minWidth ),
				areaHeight = Math.max( wsize.y - hsize.y - fsize.y ,ops.minHeight );
				
			this.els.box.set('styles',{width:Math.max( wsize.x, areaWidth + msize.x + 3 )});
			this.els.menu.set('styles',{height:areaHeight});
			this.els.content.set('styles',{height:areaHeight});
			this.els.content.set('styles',{width:areaWidth});
		},
		destroy:function(){
			this.setEvent('remove');
		}
	});

	win.addEvent('domready',function(){
		if(Browser.ie6){
			//IE6下pre标签如果不设置宽度值，无法自动给出滚动条
			//通过JS计算宽度会导致浏览器假死，尚未找到合适的解决方案。
		}else{
			var indexDocWin = new clsDocWin();
		}
	});
	
})();